package persist

import (
	"gxgeek.com/gxgeek/learngo/crawler/engine"
	"gopkg.in/olivere/elastic.v5"
	"gxgeek.com/gxgeek/learngo/crawler/persist"
	"log"
)

type ItemSaverService struct {
	Client *elastic.Client
	Index  string
}

func (s *ItemSaverService)  Save (item engine.Item,result *string) error{

	err := persist.Save(item,s.Client, s.Index, )
	log.Printf("Item %v saved.", item)
	if err == nil {
		*result = "ok"
	} else {
		log.Printf("Error saving item %v: %v",
			item, err)
	}
	return err

}